package com.woniuxy.movie.product.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.movie.commons.core.model.Result;
import com.woniuxy.movie.product.dto.session.SessionInfoDto;
import com.woniuxy.movie.product.form.session.CreateSessionForm;
import com.woniuxy.movie.product.model.ProductSession;
import com.woniuxy.movie.product.service.ProductSessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 电影场次表 前端控制器
 * </p>
 *
 * @author 刘存益
 * @since 2023年11月17日
 */
@RestController
@RequestMapping("/productSession")
@Api(tags = "电影场次相关接口")
public class ProductSessionController {

    @Autowired
    private ProductSessionService productSessionService;

    /**
     * 通过ID查询场次信息
     * @param id
     * @return
     */
    @GetMapping("/byId/{id}.api")
    @ApiOperation("查询场次信息操作")
    public Result<SessionInfoDto> byId(@PathVariable("id") Integer id){
        ProductSession productSession = productSessionService.getById(id);
        return Result.getResult(SessionInfoDto.class).setData(BeanUtil.toBean(productSession,SessionInfoDto.class));
    }

    /**
     * 修改场次信息
     * @param sid
     * @return
     */
    @PostMapping("/save.api")
    @ApiOperation("修改场次信息操作")
    public Result<Boolean> save(@RequestBody SessionInfoDto sid){
        ProductSession productSession = BeanUtil.toBean(sid, ProductSession.class);
        if (productSessionService.updateById(productSession)) {
            return Result.getResult(Boolean.class).setData(true).setMsg("修改成功");
        }
        return Result.getResult(Boolean.class).setData(false).setMsg("修改失败").setCode(500);
    }

    /**
     * 批量排场次操作
     * @param forms
     * @return
     */
    @PostMapping("/creates.api")
    @ApiOperation("批量排场次操作")
    public Result<Boolean> creates(@RequestBody List<CreateSessionForm> forms){
        Boolean bool = productSessionService.createsList(forms);
        return Result.getResult(Boolean.class).setData(bool).setMsg("批量排场次成功");
    }

}

